
$(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler: function() {
        login();
    }
});
function login() {
    $.modal.loading($("#signupForm").data("loading"));
    var companyAccount = $.common.trim($("input[name='companyAccount']").val());
    var loginName = $.common.trim($("input[name='loginName']").val());
    var loginPwd = $.common.trim($("input[name='loginPwd']").val());
    $.ajax({
        type: "post",
        url: "/meals/scan/qrcode/login",
        data: {
            "companyAccount": companyAccount,
            "loginName": loginName,
            "loginPwd": loginPwd
        },
        success: function(r) {
            if (r.code == 0) {
                location.href = '/meals/scan/qrcode/scan';
            } else {
                $.modal.closeLoading();
                $('.imgcode').click();
                $.modal.msg(r.msg || "请求有误，请联系管理员！");
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            companyAccount: {
                required: true
            },
            loginName: {
                required: true
            },
            loginPwd: {
                required: true
            }
        },
        messages: {
            companyAccount: {
                required: "",
            },
            loginName: {
                required: "",
            },
            loginPwd: {
                required: "",
            }
        }
    })
}
